package com.the.ui.page.fragment.photoview

import android.content.Context
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import com.the.ui.databinding.FragmentPhotoViewBinding
import com.theone.common.constant.BundleConstant
import com.theone.common.ext.getValueNonNull
import com.theone.common.ext.logE
import com.theone.common.ext.match_match
import com.theone.mvvm.base.viewmodel.BaseViewModel
import com.theone.mvvm.core.base.fragment.BaseCoreFragment
import com.theone.mvvm.ext.qmui.setTitleWitchBackBtn
import java.lang.reflect.Constructor

//  ┏┓　　　┏┓
//┏┛┻━━━┛┻┓
//┃　　　　　　　┃
//┃　　　━　　　┃
//┃　┳┛　┗┳　┃
//┃　　　　　　　┃
//┃　　　┻　　　┃
//┃　　　　　　　┃
//┗━┓　　　┏━┛
//    ┃　　　┃                  神兽保佑
//    ┃　　　┃                  永无BUG！
//    ┃　　　┗━━━┓
//    ┃　　　　　　　┣┓
//    ┃　　　　　　　┏┛
//    ┗┓┓┏━┳┓┏┛
//      ┃┫┫　┃┫┫
//      ┗┻┛　┗┻┛
/**
 * @author The one
 * @date 2021-11-03 17:01
 * @describe TODO
 * @email 625805189@qq.com
 * @remark
 */
class PhotoViewFragment private constructor() :
    BaseCoreFragment<BaseViewModel, FragmentPhotoViewBinding>() {

    companion object {
        fun newInstance(type: String): PhotoViewFragment {
            return PhotoViewFragment().apply {
                arguments = Bundle().apply {
                    putString(BundleConstant.DATA, type)
                }
            }
        }
    }

    private val mType: String by getValueNonNull(BundleConstant.DATA)

    override fun initView(root: View) {
        setTitleWitchBackBtn(mType)

        var clazz: Class<out View>? = null
        var constructor: Constructor<out View>? = null
        try {
            clazz = Class.forName("com.the.ui.widge.photoview.$mType", false, mActivity.classLoader)
                .asSubclass(
                    View::class.java
                )
            constructor = clazz.getConstructor(Context::class.java)
            constructor.isAccessible = true
            val view: View? = constructor.newInstance(context)
            mBinding.container.addView(view, match_match)
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

    override fun createObserver() {

    }


}